package net.amitabul.slrclub;


import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import android.util.Log;

import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.Source;
import net.htmlparser.jericho.StartTag;

public class ParseUsedMarket {
	ParseUsedMarket(String html) throws MalformedURLException, IOException {
		mSource = new Source(html);		
	}
	
	/*public List<Item> getItems() {
		Vector<Item> list = new Vector<Item>();		
		
	}*/
	
	public void parsing() {
		mSource.fullSequentialParse();
		
		boolean notify = false;
		
		
		List<Element> divList = mSource.getAllElements(HTMLElementName.LI);
		Iterator<Element> divIter = divList.iterator();
		int i = 0;
		while(divIter.hasNext()) {
			Element liElement = (Element) divIter.next();
			i++;
			if (i < 19) {
				continue;
			}
			
			List<Element> aElementList = liElement.getAllElements(HTMLElementName.A);
			Element aElement = (Element)aElementList.get(0);
			String title = aElement.getTextExtractor().toString();
			String link = aElement.getAttributeValue("href");
			
			List<Element> divElementList = liElement.getAllElements(HTMLElementName.DIV);
			Element divElement = (Element)divElementList.get(2);
			String[] contents = divElement.getContent().toString().split("[|]");
			
			Item item = new Item(title, contents[0].trim(), link, contents[2].trim());
			mItems.add(item);
			
			
			Log.d(this.getClass().getName(), title);
			Log.d(this.getClass().getName(), link);
			Log.d(this.getClass().getName(), contents[0].trim());
			Log.d(this.getClass().getName(), contents[1].trim());
			Log.d(this.getClass().getName(), contents[2].trim());
			
		}
	}
	
	public int getItem(int index) {
		return mItems.size();
	}

	private Source mSource = null;	
	private Vector<Item> mItems = new Vector<Item>(20);
}


